<template>
	<view class="w100p flex-column pr common_wrap">
		<image class="flex-none img" src="@/static/detail/icon.png" mode="widthFix"></image>
		<!-- <a id="app-link" href="javascript:;" @click="jumpTo(bid, type)">打开APP</a> -->
		<view class="w100p pa btn_wrap">
			<view class="w100p btn btn_01" @click="jumpTo(bid, type)">
				{{ lang == "zh-cn" ? "打开" : "Скачать" }}
			</view>
			<!-- <view class="w100p btn btn_02" @click="jumpTo(bid, type)">
				{{ lang == "zh-cn" ? "打开" : "Открыть" }}
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bid: "",
				type: "",
				lang: "",
				offerId: '',
				offer_price: '',
			}
		},
		async mounted() {
			this.bid = await this.getUrlParam1("bid");
			this.type = await this.getUrlParam1("type");
			this.offerId = await this.getUrlParam1("offerId");
			this.offer_price = await this.getUrlParam1("offer_price");
			this.lang = (navigator.browserLanguage || navigator.language).toLowerCase();
			setTimeout(() => {
				this.jumpTo(this.bid, this.type);
			}, 1000)
		},
		methods: {
			// switch (+type) {
			// 				case 1:
			// 					url = `/pages/details/shopDetail?id=${bid}` // 商品详情
			// 					break;
			// 				case 2:
			// 					url = `/pages/details/carDetail?id=${bid}` // 汽车详情
			// 					break;
			// 				case 3:
			// 					url = `/pages/details/shopDetail1688?id=${bid}&offerId=${offerId}&offer_price=${offer_price}` // 1688详情
			// 					break;
			// 				case 4:
			// 					url = `/pages/details/merchantDetail?bid=${bid}` // 店铺详情
			// 					break;
			// 			}
			jumpTo(bid, type) {

				console.log( `gluzshop://page?url=/pages/details/shopDetail?bid=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`,'参数参数参数')
				// 微信中在浏览器中打开
				if (navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1) {
					// 微信内
					uni.showModal({
						title: this.lang == 'zh-cn' ? '提示' : 'Предупреждение',
						content: this.lang == 'zh-cn' ? '请在浏览器中打开这个链接，下载或者打开app' : 'Пожалуйста, откройте эту ссылку в браузере, чтобы скачать или открыть приложение',
						confirmText: this.lang == 'zh-cn' ? '确定' : 'ОК',
						cancelText: this.lang == 'zh-cn' ? '取消' : 'Отмена',
					})
				} else {
					if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {

						switch(+type) {
							case 1: // 商品详情
								window.location.href = `gluzshop://page?url=/pages/details/shopDetail?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 2: // 汽车详情
								window.location.href = `gluzshop://page?url=/pages/details/carDetail?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 3: // 1688详情
								window.location.href = `gluzshop://page?url=/pages/details/shopDetail1688?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 4: // 店铺详情
								window.location.href = `gluzshop://page?url=/pages/details/merchantDetail?bid=${bid}&type=${type}`; 
								break;
						}

						// if (bid) {
						// 	window.location.href = `gluzshop://page?url=/pages/details/merchantDetail?bid=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
						// } else {
						// 	window.location.href = `gluzshop://page?bid=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
						// }

						setTimeout(function() {
							window.location.href = "https://apps.apple.com/us/app/gluz/id6502644536?l=zh-Hans-CN";
						}, 2000)
					}
					if (navigator.userAgent.match(/android/i)) {
						// window.location.href = `gluzshop://page?bid=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; //android app协议
						switch(+type) {
							case 1: // 商品详情
								window.location.href = `gluzshop://page?url=/pages/details/shopDetail?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 2: // 汽车详情
								window.location.href = `gluzshop://page?url=/pages/details/carDetail?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 3: // 1688详情
								window.location.href = `gluzshop://page?url=/pages/details/shopDetail1688?id=${bid}&type=${type}&offerId=${this.offerId}&offer_price=${this.offer_price}`; 
								break;
							case 4: // 店铺详情
								window.location.href = `gluzshop://page?url=/pages/details/merchantDetail?bid=${bid}&type=${type}`; 
								break;
						}
						setTimeout(function() {
							window.location.href = "https://oss.gluz.com.cn/download/app.apk"; //android 下载地址
						}, 2000)
					}
				}


			},
			getUrlParam1(key) {
				try {
					const href = window.location.href;
					const reg = new RegExp(`${key}=[^&|#|\/]*`);
					const res = href.match(reg);
					return res ? href.match(reg)[0].split('=')[1] : '';
				} catch (error) {
					alert(error)
				}
			},
		}
	}
</script>

<style scoped lang="less">
	.common_wrap {
		justify-content: center;

		.img {
			width: 240rpx;
			height: 240rpx;
		}

		.btn_wrap {
			position: absolute;
			bottom: 60rpx;
			left: 0;
			padding: 0 24rpx;
			text-align: center;

			.btn {
				width: 100%;
				height: 90rpx;
				line-height: 90rpx;
				border-radius: 16rpx;
				font-size: 32rpx;
				font-weight: 700;

				&.btn_01 {
					color: #fff;
					background: linear-gradient(to bottom, #4BADFD 0%, #2B61EB 100%);
					margin-bottom: 24rpx;
				}

				&.btn_02 {
					color: #262728;
					background: #E1E1E1;
				}
			}
		}
	}
</style>